package ejb.cbm.admin.session;

import java.util.List;

import javax.persistence.EntityManager;

import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import ejb.cbm.admin.entity.TransaccionSegmentoEntity;
import ejb.cbm.admin.entity.TransaccionSegmentoEntityId;
import ejb.cbm.admin.local.TransaccionSegmentoSessionLocal;

////@Stateless
public class TransaccionSegmentoSession extends HibernateDaoSupport  implements TransaccionSegmentoSessionLocal {
	
	static Logger logger = Logger.getLogger(TransaccionSegmentoSession.class.getName());
	//property constants
	public static final String MONTOSINAUTORIZACIONSOLES = "montosinautorizacionsoles";
	public static final String MONTOCONAUTORIZACIONSOLES = "montoconautorizacionsoles";
	public static final String MONTOSINAUTORIZACIONDOLARES = "montosinautorizaciondolares";
	public static final String MONTOCONAUTORIZACIONDOLARES = "montoconautorizaciondolares";
	public static final String MONTOSINAUTORIZACIONEUROS = "montosinautorizacioneuros";
	public static final String MONTOCONAUTORIZACIONEUROS = "montoconautorizacioneuros";
	public static final String USUARIOREGISTRO = "usuarioregistro";
	public static final String USUARIOMODIFICACION = "usuariomodificacion";


    //@PersistenceContext 
	private EntityManager entityManager;
    public void save(TransaccionSegmentoEntity transientInstance) {
    	logger.log("saving TransaccionSegmentoEntity instance", Level.INFO, null,null);
        try {
            entityManager.persist(transientInstance);
            logger.log("save successful", Level.INFO, null,null);
        } catch (RuntimeException re) {
        	logger.log("save failed", Level.FATAL,null, re);
            throw re;
        }
    }
    
    public void delete(TransaccionSegmentoEntity persistentInstance) {
    	logger.log("deleting TransaccionSegmentoEntity instance", Level.INFO, null,null);
        try {
            entityManager.remove(persistentInstance);
            logger.log("delete successful", Level.INFO, null,null);
        } catch (RuntimeException re) {
        	logger.log("delete failed", Level.FATAL,null, re);
            throw re;
        }
    }
    
    public TransaccionSegmentoEntity update(TransaccionSegmentoEntity detachedInstance) {
    	logger.log("updating TransaccionSegmentoEntity instance", Level.INFO, null,null);
        try {
            TransaccionSegmentoEntity result = entityManager.merge(detachedInstance);
            logger.log("update successful", Level.INFO, null,null);
            return result;
        } catch (RuntimeException re) {
        	logger.log("update failed", Level.FATAL,null, re);
            throw re;
        }
    }
    
    public TransaccionSegmentoEntity findById( TransaccionSegmentoEntityId id) {
    	logger.log("finding TransaccionSegmentoEntity instance with id: " + id, Level.INFO, null,null);
        try {
            TransaccionSegmentoEntity instance = entityManager.find(TransaccionSegmentoEntity.class, id);
            return instance;
        } catch (RuntimeException re) {
        	logger.log("find failed", Level.FATAL,null, re);
            throw re;
        }
    }
    
    //@SuppressWarnings("unchecked")
    public List<TransaccionSegmentoEntity> findByProperty(String propertyName, Object value) {
    	logger.log("finding TransaccionSegmentoEntity instance with property: " + propertyName
    						+ ", value: " + value, Level.INFO, null,null);
		try {
			String queryString = "select model from TransaccionSegmentoEntity model where model." 
			 						+ propertyName + "= :propertyValue";
			return entityManager.createQuery(queryString)
 				.setParameter("propertyValue", value).getResultList();
		} catch (RuntimeException re) {
			logger.log("find by property name failed", Level.FATAL,null, re);
			throw re;
		}
	}
	
	public List<TransaccionSegmentoEntity> findByMontosinautorizacionsoles(Object montosinautorizacionsoles) {
		return findByProperty(MONTOSINAUTORIZACIONSOLES, montosinautorizacionsoles);
	}
	
	public List<TransaccionSegmentoEntity> findByMontoconautorizacionsoles(Object montoconautorizacionsoles) {
		return findByProperty(MONTOCONAUTORIZACIONSOLES, montoconautorizacionsoles);
	}
	
	public List<TransaccionSegmentoEntity> findByMontosinautorizaciondolares(Object montosinautorizaciondolares) {
		return findByProperty(MONTOSINAUTORIZACIONDOLARES, montosinautorizaciondolares);
	}
	
	public List<TransaccionSegmentoEntity> findByMontoconautorizaciondolares(Object montoconautorizaciondolares) {
		return findByProperty(MONTOCONAUTORIZACIONDOLARES, montoconautorizaciondolares);
	}
	
	public List<TransaccionSegmentoEntity> findByMontosinautorizacioneuros(Object montosinautorizacioneuros) {
		return findByProperty(MONTOSINAUTORIZACIONEUROS, montosinautorizacioneuros);
	}
	
	public List<TransaccionSegmentoEntity> findByMontoconautorizacioneuros(Object montoconautorizacioneuros) {
		return findByProperty(MONTOCONAUTORIZACIONEUROS, montoconautorizacioneuros);
	}
	
	public List<TransaccionSegmentoEntity> findByUsuarioregistro(Object usuarioregistro) {
		return findByProperty(USUARIOREGISTRO, usuarioregistro);
	}
	
	public List<TransaccionSegmentoEntity> findByUsuariomodificacion(Object usuariomodificacion) {
		return findByProperty(USUARIOMODIFICACION, usuariomodificacion);
	}
	

	//@SuppressWarnings("unchecked")
	public List<TransaccionSegmentoEntity> findAll() {
		logger.log("finding all TransaccionSegmentoEntity instances", Level.INFO, null,null);
		try {
			String queryString = "select model from TransaccionSegmentoEntity model";
			return entityManager.createQuery(queryString).getResultList();
		} catch (RuntimeException re) {
			logger.log("find all failed", Level.FATAL,null, re);
			throw re;
		}
	}
}